/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rooster.test;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rooster.manager.TaskManager;

/**
 *
 * @author Savithri
 */
public class ResourceRequirementComparison {

    Connection con = null;
    final String url = "jdbc:mysql://localhost:3306/";
    final String db = "resources";
    final String driver = "com.mysql.jdbc.Driver";
    public String employeePriority;

    public Vector getRequirement() throws SQLException {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ResourceRequirementComparison.class.getName()).log(Level.SEVERE, null, ex);
        }
        con = (Connection) DriverManager.getConnection(url + db, "root", "");

        Vector <Vector<Vector>>totalRequirementVec = new Vector<Vector<Vector>>();
        for (int section = 0; section < TaskManager.NO_OF_SECTIONS; section++) {
            Vector<Vector> sectionReq = new Vector();


            for (int timeslot = 0; timeslot < TaskManager.NO_OF_TIME_SLOTS; timeslot++) {
                int volcount = 0;
                int nonVolcount = 0;
                Vector timeSlotReq = new Vector();

                PreparedStatement requirement = (PreparedStatement) con.prepareStatement("select * from resource_requirement where  task='" + section + "' and time_slot='" + timeslot + "'");
                ResultSet requiremetResultSet = requirement.executeQuery();

                while (requiremetResultSet.next()) {
                    int timeSlotRequirement = requiremetResultSet.getInt(4);
                    String type = requiremetResultSet.getString(3);
                    if (type.equals("VOLUME")) {
                        volcount = volcount + timeSlotRequirement;
                    } else {
                        nonVolcount = nonVolcount + timeSlotRequirement;
                    }

                }
                timeSlotReq.add(volcount);
                timeSlotReq.add(nonVolcount);
                sectionReq.add(timeSlotReq);

            }
            totalRequirementVec.add(sectionReq);

        }

        if (con != null) {
            con.close();
        }
     //   System.out.println(totalRequirementVec);
        return totalRequirementVec;
    }

    public Vector getFulfilledRequirement() throws SQLException {

        try {
            Class.forName(driver);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ResourceRequirementComparison.class.getName()).log(Level.SEVERE, null, ex);
        }
        con = (Connection) DriverManager.getConnection(url + db, "root", "");


        Vector<Vector<Vector>>totalfulfilledRequirementVec = new Vector<Vector<Vector>>();
        for (int section = 0; section < TaskManager.NO_OF_SECTIONS; section++) {
            int finalSectionRequirementCount = 0;


            Vector<Vector> finalFulfilledRequiermet = new Vector();

            for (int timeslot = 0; timeslot < TaskManager.NO_OF_TIME_SLOTS; timeslot++) {
                int volumeCount = 0;
                int nonvolumeCount = 0;
                Vector fulfilledRequiermet = new Vector();
                PreparedStatement requirement = (PreparedStatement) con.prepareStatement("select * from schedule where  task='" + section + "' and time_slot='" + timeslot + "'");
                ResultSet requiremetResultSet = requirement.executeQuery();

                while (requiremetResultSet.next()) {

                    String type = requiremetResultSet.getString(3);
                    if (type.equals("VOLUME")) {
                        volumeCount++;

                    } else {
                        nonvolumeCount++;
                    }


                }
                fulfilledRequiermet.add(volumeCount);
                fulfilledRequiermet.add(nonvolumeCount);

                finalFulfilledRequiermet.add(fulfilledRequiermet);


                finalSectionRequirementCount = finalSectionRequirementCount + (volumeCount + nonvolumeCount);
            }
            totalfulfilledRequirementVec.add(finalFulfilledRequiermet);

        }
      //  System.out.println(totalfulfilledRequirementVec);
        if (con != null) {
            con.close();
        }


return  totalfulfilledRequirementVec;


    }

}

